<?php

class RegistrationsController extends AppController{

	var $helpers = array('Html', 'Form', 'Session');

	var $scaffold;

	function beforeFilter() {

		$this->Auth->allow('*');
		parent::beforeFilter();
	}

	function display2($id = null) {


	if(empty($this->data)){
		$sFilter = " user_id = '$id' ";
		$this->data = $this->Registration->findAll($sFilter);
//		$this->set('aData', $this->Registration->find($sFilter, null, null, null, null, 2));
	}
	else{
		if($this->Registration->save($this->data)){
			$this->flash('passt', 'asdf', 2);
		}
	


		
	}
	}
	function displaysingle($id = null){
		if (empty($this->data)) {
			$sFilter = " user_id = '$id' ";
			$this->data = $this->Registration->find($sFilter);
		} else {
				$this->Registration->save($this->data);
		}
	}

	function display($id = null){
		if (empty($this->data)) {
			$sFilter = " user_id = '$id' ";
			$this->data = $this->Registration->findAll($sFilter);
		} else {
			foreach($this->data as $index => $book) {
				$this->Registration->create();
				$this->Registration->set($book);
				$this->Registration->save();
			}
		}
	}

function editxxx(){
  if (!empty($this->data)) {
    if ($this->Author->save()) {
      // grab the id of the Author we just saved
      $author_id = $this->Author-id;

      $invalidBookFields = array();
      foreach($this->data['Book'] as $index => $book) {
        $book = array('Book' => $book);
        $book['Book']['author_id'] = $author_id;

        // clear any previous Book data
        $this->Author->Book->create();
        // We set the Book data this way so that validation is processed correctly
        $this->Author->Book->set($book);
        if (!$this->Author->Book->validates()) {
          // save the validationErrors and reset for the next iteration
          $invalidBookFields[$index] = $this->Author->Book->validationErrors;
          unset($this->Author->Book->validationErrors);
        } else {
          $this->Author->Book->save();
        }
      }

      if (empty($invalidBookFields)) {
      	// success - set message or redirect
      } else {
      	// put all the errors back in the model so they make it back to the view
      	$this->Author->Book->validationErrors = $invalidBookFields;
      }
    }
  }
}


}
?>


